import axios from './http';
//  首页数据接口
const homePage = async () => {
    let data = await axios({
        method: 'get',
        url: '/api/statistic/base_count.do',
    });
    return data
}
// 登录接口
const login = async (formData) => {
    let data = await axios({
        method: 'post',
        url: '/api/user/login.do',
        params: {
            username: formData.username,
            password: formData.password
        }
    });
    return data
}
// 商品列表接口
const shop = async (pageNum) => {
    let data = await axios({
        method: 'post',
        url: '/api/product/list.do?pageNum=' + pageNum,
        data: {
            pageNum
        }
    });
    return data
}
//   用户管理接口
const getUserList = async (pageNum) => {
    let data = await axios({
        method: 'post',
        url: '/api/user/list.do?pageNum=' + pageNum,
        data: {
            pageNum
        }
    });
    return data
}
//  搜索接口 
// product/search.do?listType=search&pageNum=1&productId=88
const search = async (pageNum, key, searchKey) => {
    let data = await axios({
        method: 'post',
        url: `/api/product/search.do?listType=search&pageNum=${pageNum}&${searchKey}=${key}`,
    });
    return data
}
// 品类管理接口
const getClassifyList = async () => {
    let data = await axios({
        method: 'get',
        url: '/api/category/get_category.do?categoryId=0',
    });
    return data
}
//   订单管理接口 
const getOrderList = async (pageNum) => {
    let data = await axios({
        method: 'post',
        url: '/api/order/list.do?pageNum=' + pageNum,
    });
    return data
}
// 订单详情接口 
const getOrderDetail = async (orderNo) => {
    let data = await axios({
        method: 'post',
        url: '/api/order/detail.do?orderNo=' + orderNo,
    });
    return data
}
// 添加商品列表接口  category/get_category.do?categoryId=0
const addShop = async (id) => {
    let data = await axios({
        method: 'get',
        url: `/api/category/get_category.do?categoryId=${id}`,
    });
    return data
}
//  提交添加接口 
// category/add_category.do?parentId=100003&categoryName=%E5%B0%8F%E7%B1%B3%E7%94%B5%E8%A7%86
const confirmAdd = async (id, shopName) => {
    let data = await axios({
        method: 'get',
        url: `/api/category/add_category.do?parentId=${id}&categoryName=${shopName}`,
    });
    return data
}
// category/set_category_name.do?categoryId=100002&categoryName=%E5%86%B0%E7%AE%B1  修改品类名称接口
const updateClassify = async (id, name) => {
    let data = await axios({
        method: 'get',
        url: `/api/category/set_category_name.do?categoryId=${id}&categoryName=${name}`,
        data: {
            categoryId: id,
            categoryName: name
        }
    });
    return data
}
// product/save.do   编辑提交 以及添加商品  接口  
const editShop = async (obj) => {
    let data = await axios({
        method: 'get',
        url: `/api/product/save.do`,
        params: obj
    });
    return data
}
// 查看子类产品  category/get_category.do?categoryId=100001
// const lookChild = async (id) => {
//     let data = await axios({
//         method: 'get',
//         url: `/api/category/get_category.do?categoryId=${id}`,
//     });
//     return data
// }
// 查看商品详情  product/detail.do?productId=2
const shopDetail = async (id) => {
    let data = await axios({
        method: 'get',
        url: `/api/product/detail.do?productId=${id}`,
    });
    return data
}
//   上架下架切换接口
const changeStatus = async (list) => {
    let data = await axios({
        method: 'get',
        url: `/api/product/set_sale_status.do?productId=${list.id}&status=${list.status}`,
        data: {
            productId: list.id,
            status: list.status
        }
    });
    return data
}
// 
export {
    homePage, login, shop, getUserList, getClassifyList, getOrderList, getOrderDetail, changeStatus, search, addShop
    , updateClassify, confirmAdd, shopDetail, editShop
}